package com.ftg.learn.myinterface;

import com.ftg.learn.myinterface.entity.ShopProductEntity;
import com.ftg.learn.myinterface.mapper.ShopProductMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @author 布衣
 */
public class TestInterfaceModel {

    public static void main(String[] args) throws IOException {
        String path = "myinterface/config.xml";
        Reader reader = Resources.getResourceAsReader(path);
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = builder.build(reader);
        //以上创建完成了工厂
        SqlSession sqlSession = factory.openSession();

        //获取映射器
        ShopProductMapper mapper = sqlSession.getMapper(ShopProductMapper.class);

        ShopProductEntity s = new ShopProductEntity();
        s.setProName("测试商品");
        s.setProPrice(new BigDecimal("20.24"));
        s.setProDesc("测试商品描述");
        s.setProStatus((byte) 0);
        s.setProType((byte) 0);
        s.setProNum(10);
        s.setProCategoryId(1L);
        s.setGmtModify(LocalDateTime.now());
        s.setGmtCreate(LocalDateTime.now());

//        int num = mapper.add(s);
//
//
//        System.out.println("添加了商品数量：" + num);
//        System.out.println(mapper.list());
//
//
//        System.out.println("=="+mapper.getOneById(1L));

//        mapper.listByParameter("测试",(byte)1,"0");
        mapper.delByIds(Arrays.asList(4L, 5L, 6L, 7L));

        sqlSession.commit();
    }

}
